﻿/* 
 * author: www.cnblogs.com/luminji
 * date  : 2011/12/28
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Luminji.Exam.Model;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;

namespace Luminji.ExamWeb.Helpers
{
    public class UnityControllerFactory : DefaultControllerFactory
    {
        IUnityContainer _container;
        public UnityControllerFactory(IUnityContainer container)
        {
            this._container = container;
        }

        protected override IController GetControllerInstance(RequestContext reqContext,
            Type controllerType)
        {
            if (controllerType == null)
            {
                return null;
            }
            _container.Configure<Interception>().SetInterceptorFor(controllerType, new VirtualMethodInterceptor());
            //_container.Configure<Interception>().SetInterceptorFor(controllerType, new InterfaceInterceptor());
            return _container.Resolve(controllerType) as IController;
        }
    }
}